package com.kl.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kl.domain.TbContactsDTO;
import com.kl.entity.TbContacts;
import com.kl.entity.User;
import com.kl.mapper.TbContactsMapper;
import com.kl.service.ITbContactsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2021-10-29
 */
@Service
public class TbContactsServiceImpl extends ServiceImpl<TbContactsMapper, TbContacts> implements ITbContactsService {

    @Autowired
    private TbContactsMapper contactsMapper;

    @Override
    public List<TbContactsDTO> selectByUserName(String userName) {
        QueryWrapper<TbContacts> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(userName), "tb_contactsname", userName);
        List<TbContacts> tbContacts = contactsMapper.selectList(queryWrapper);
        String string = JSONObject.toJSONString(tbContacts);
        List<TbContactsDTO> tbContactsDTOS = JSONObject.parseArray(string, TbContactsDTO.class);
        return tbContactsDTOS;
    }

    @Override
    public void insertInto(TbContacts tbContacts) {
        contactsMapper.insert(tbContacts);
    }

    @Override
    public void deleteBatchIds(List<Integer> asList) {
        contactsMapper.deleteBatchIds(asList);
    }
}
